home *** CD-ROM | disk | FTP | other *** search
/ C/C++ Users Group Library 1996 July / C-C++ Users Group Library July 1996.iso / vol_400 / 431_01 / rstatus.c < prev    next >
Text File  |  1994-10-07  |  3KB  |  105 lines

  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <dos.h>
  4. #include <time.h>
  5. #include <conio.h>
  6. #include "math.h"
  7. #include "ifs.h"
  8. #include "rifs.h"
  9. #include "rclient.h"
  10.  
  11. void ShowStat(char *title, IFS_STAT *st)
  12. {
  13.     printf("%-40sFailures\n"
  14.            "Total bytes sent: %10ld                    timeout: %10ld\n"
  15.            "        recieved: %10ld                    CRC:     %10ld\n"
  16.            "           valid: %10ld                    length:  %10ld\n"
  17.            "                  %13.2f         Stack used:      %10u\n",
  18.            title,
  19.            st->totalsent, st->timeout,
  20.            st->totalrcvd, st->crcfail,
  21.            st->valid,     st->lenfail,
  22.            (float) 100.0 * st->valid/(st->totalrcvd ? st->totalrcvd : 1),
  23.            st->stackused);
  24. }
  25.  
  26. void ShowOpenFile(unsigned handle, unsigned psp)
  27. {
  28.   struct REGPACK regs;
  29.   SYS_FTAB **first,
  30.             *next;
  31.   int handno,
  32.       ii,
  33.       sftlen=(_osmajor == 3) ? 0x35 : 0x3b;
  34.  
  35.   regs.r_ax=0x5200;
  36.   intr(0x21, ®s);
  37.   first=MK_FP(regs.r_es, regs.r_bx+4);
  38.   next = *first;
  39.   handno=0;
  40.   do {
  41.     for (ii=0; ii < next->num_files; ii++) {
  42.       SFT *t=(SFT *) (next->files + ii*sftlen);
  43.       if (handno == handle) {
  44.         printf("%4x : %11.11s\n",
  45.           psp, t->fcb_name);
  46.         return;
  47.       }
  48.       handno++;
  49.     }
  50.     next=next->next;
  51.   } while (FP_SEG(next) && (FP_OFF(next) != 0xffff));
  52.   printf("%4x : {invalid file handle}\n", psp);
  53. }
  54.  
  55. void ShowServerStat(char *title, IFS_STAT *st)
  56. {
  57.   int ii, flag=0;
  58.  
  59.   ShowStat(title, st);
  60.   printf("Number of server calls: %10ld\n", st->inserver);
  61.   for (ii=0; ii < MAXOPEN; ii++) {
  62.     if (st->openpsp[ii]) {
  63.       if (!flag) {
  64.         printf("Open files:\n");
  65.         flag=1;
  66.       }
  67.       ShowOpenFile(st->openhandle[ii], st->openpsp[ii]);
  68.     }
  69.   }
  70.   if (!flag)
  71.     printf("No Open Files\n");
  72. }
  73.  
  74. void main(void)
  75. {
  76.   int RIFS=FindRIFS();
  77.   struct REGPACK regs;
  78.   int key=0;
  79.   long now=0, last=0;
  80.  
  81.   if (!RIFS) {
  82.     fprintf(stderr, "Cannot locate RIFS\n");
  83.     exit(1);
  84.   }
  85.   clrscr();
  86.   do {
  87.     time(&now);
  88.     if (labs(now-last) >= 1) {
  89.       last=now;
  90.       gotoxy(1,1);
  91.       regs.r_ax=RCLIENT_GETSTAT;
  92.       intr(RIFS, ®s);
  93.       if (!(regs.r_flags & 0x01))
  94.         ShowStat("RCLIENT", MK_FP(regs.r_es, regs.r_bx));
  95.       regs.r_ax=RSERVER_GETSTAT;
  96.       intr(RIFS, ®s);
  97.       if (!(regs.r_flags & 0x01)) {
  98.         ShowServerStat("RSERVER", MK_FP(regs.r_es, regs.r_bx));
  99.       }
  100.     }
  101.     if (kbhit())
  102.       key=getch();
  103.   } while (key != 27);
  104. }
  105.